package LeetcodeTest_seven;

import java.util.ArrayList;

//整数拆分
public class integerBreak
{
    public static void main(String[] args)
    {
        System.out.println(solution.integerBreak(9));
    }
}
class solution
{
    public static int integerBreak(int n)
    {
        int result=1;
        int length=n;
        int j=0;
        int num[]=new int[n];
        for (int i=0;i<n;i++)
            num[i]=1;
        for (int i=0;i<n-1;i++)
        {
            int answer=multiply(num,length);
            if (result<answer)
                result=answer;
            while(length>2)
            {
                if (j==length)
                    j = 0;
                num[j]++;
                num[length-1]--;
                j++;
                if(num[length-1]==0)
                    break;
            }
            length--;
        }
        return result;
    }
    public static int multiply(int num[],int length)
    {
        int multiply=1;
        for (int i=0;i<length;i++)
            multiply=multiply*num[i];
        return multiply;
    }
}